home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-04 | 12.1 KB | 338 lines | [TEXT/MPS ] |
- #
- # File: StandardDialogs.vulib
- #
- # Contains: Sample tasks for working with standard Macintosh dialogs
- #
- # Written by: Sean Flynn, Jay Jessen, and P. Nagarajan
- #
- # Copyright: © 1990-1992 by Apple Computer, Inc., all rights reserved.
- #
- # Change History (most recent first):
- #
- # <5> 1/17/97 AR Changed SetPaper task to handle page size popups
- # 8/5/92 DGG Added ColorPicker dialog handler.
- # <4> 6/16/92 DGG Added tasks to handle page setup dialog
- # StandardDialogs.vulib now uses UtilityTasks.vulib
- # <3> 8/26/91 Rick Marked new tasks
- # <2> 7/18/91 NAGA update with changes made by David Gaxiola
- # for running against System 7.0
- # <1+> 7/18/91 NAGA update with changes made by David Gaxiola for
- # running against System 7.0
- # 4/25/89 SLF Created.
- #
- # To Do:
- #
-
- Libraries "UtilityTasks.vulib";
-
- (************************************************************************************
- * Task ColorPicker(hue, saturation, brightness, red, green, blue)
- * Handle standard Macintosh color picker dialog. The values supplied correspond
- * to the six fields available for typing. If no change is desired, don't specify
- * anything for a particular trait.
- ************************************************************************************)
- task ColorPicker(hue := undefined, saturation := undefined, brightness := undefined,
- red := undefined, green := undefined, blue := undefined)
- begin
- FindObjectInWindow(122, 146);
- doubleClick;
- if hue
- type k:{hue};
- type k:{tabKey};
-
- if saturation
- type k:{saturation};
- type k:{tabKey};
-
- if brightness
- type k:{brightness};
- type k:{tabKey};
-
- if red
- type k:{red};
- type k:{tabKey};
-
- if green
- type k:{green};
- type k:{tabKey};
-
- if blue
- type k:{blue};
- type k:{tabKey};
-
- select [button t:"OK"];
- end;
-
- (************************************************************************************
- * Task DoSaveAs( saveTitle := 'Untitled' ) begin
- * Handle a simple case of work with the Standard file dialog.
- ************************************************************************************)
- task DoSaveAs( saveTitle := 'Untitled' )
- begin
- wType := dialog; #see if dialog appeared
- wButton1 := "Replace"; #buttons to check for
- wButton2 := "Yes";
- select [menuItem t:/Save As≈/]; #menu selection
- type k:{ saveTitle }; #literal key strokes
- select [button t:"Save"]; #button press
- # if the file exists, the "Do you want to replace" dialog will come up
- # These if statements recognize that dialog and deal with it
- if match[window s:wType] do begin
- if match[button t:wButton1 e:false] do
- select[button t:wButton1];
- else if match[button t:wButton2 e:false] do
- select[button t:wButton2];
- end;
- end; # task DoSaveAs
-
-
- (************************************************************************************
- * Task SelectFromStandardFile(pathToFile,maximumNestingDepth)
- * This task will select a file from the standard file dialog. It
- * navigates through the dialog by way of the keyboard.
- * It takes two parameters, one is a list of file prefixes that will take
- * the virtual user down to the file you want selected. The list must
- * contain the strings that VU can type to reach the file. They may be the
- * complete folder names or enough of the folder name to distinguish them
- * from sibling folders. The second is a number indicating the current
- * directory's maximum depth. VU uses this number to get up to the top using
- * command-up arrow. By default, it is 15 so it isn't necessary to pass
- * the second parameter. The operation may be made faster, however, if you
- * pass it a smaller number. A sample call might look like this:
- *
- * SelectFromStandardFile( { "HD","MPW","Interf","Cinclu","Palettes" },10 );
- *
- * Because System 7.0 now has a "Desktop" in the FileSelector instead of a "Drive"
- * button, be sure to include the desktop level when setting nesting depth and
- * in the path.
- *
- * To only go back a specific number of folders as opposed to going all the way
- * to the root level, set the maximumNestingDepth to the number of folders that
- * you wish to go back.
- *
- * NOTE: VU 2.0 Change in Functionality from VU 1.x!
- * SelectFromStandardFile will now automatically press the return key at the
- * end to actually select the currently highlighted file. To disable the
- * automatic selection, set selectFile to false.
- ************************************************************************************)
- task SelectFromStandardFile(pathToFile,maximumNestingDepth := 15, selectFile := true)
- begin
- pressKey k: { commandKey };
- for i := 1 to maximumNestingDepth
- type k:{ upArrowKey };
- releaseKey k: { commandKey };
- pathSize := card(pathToFile);
- match [system v:?sysVer];
- if sysVer ~= /7≈/
- for i := 1 to pathSize - 1
- type k:{pathToFile[i],returnKey};
- else
- for i := 2 to pathSize - 1
- type k:{ pathToFile[i],returnKey };
- type k: { pathToFile[pathSize] };
- if selectFile
- type k:{ returnKey };
- end;
-
- (************************************************************************************
- * Task MakePageSetupActive()
- * To be used by pageSetup() ... see below.
- * Will check if a modal dialog is present and hopefully dispose of it. Then it
- * will open the Page Setup dialog.
- ************************************************************************************)
- task MakePageSetupActive()
- begin
- match [window o:1 s:?winStyle];
- if (winStyle = dialog)
- select [button t:"OK" w:[window o:1]];
- select [menuItem t:"Page Setup…" m:[menu t:"File"]];
- end;
-
- (************************************************************************************
- * Task SetPaper(paperSize := "USLetter")
- * To be used by pageSetup() ... see below.
- * Will choose the appropriate size of paper in the Page Setup dialog.
- ************************************************************************************)
- task SetPaper(paperSize := "USLetter", printerType := "LaserWriter")
- begin
- if #a popup is used for "paper" or "page size", use a match for each device
- # Chooser allows
- match [statictext t: "LaserWriter 300 Page Setup" w:1] or
- match [statictext t: "LaserWriter 8 Page Setup" w:1] or
- match [statictext t: "StyleWriter II Page Setup" w:1]
- begin
- match [window r: ?winCoord o:1];
- paperCoord := locatestring ("Paper",winCoord,Chicago,12,,,,);
- if isundefined (paperCoord)
- paperCoord := locatestring ("Page Size",winCoord,Chicago,12,,,,);
- if isundefined (paperCoord)
- println "neither page size nor paper was found";
- else
- begin
- move a:{paperCoord[3] + 50, paperCoord[2] + 6};
- pressmouse;
- popupCoord := 0;
- switch paperSize
- begin
- case "USLetter" :
- popupCoord := locatestring ("US Letter",winCoord,Chicago,12,,anyColor,anyColor,);
- case "USLegal" :
- popupCoord := locatestring ("US Legal",winCoord,Chicago,12,,anyColor,anyColor,);
- case "A4Letter" :
- popupCoord := locatestring ("A4",winCoord,Chicago,12,,anyColor,anyColor,);
- case "B5Letter" :
- popupCoord := locatestring ("B5",winCoord,Chicago,12,,anyColor,anyColor,);
- end;
- if isundefined (popupCoord)
- println "### Unknown paper size for driver specified! No action taken!";
- else
- move a: {(popupCoord[3] - popupCoord[1]) / 2 + popupCoord[1],
- (popupCoord[4] - popupCoord[2]) / 2 + popupCoord[2]};
- releasemouse;
- end;
- end;
- else
- begin
- #radiobuttons are used for paper size
- #devices are: LaserWriter Select 310
- # LaserWriter
- # AppleTalk ImageWriter
- # ImageWriter
- # Personal LaserWriter SC
- if paperSize = "USLetter"
- select [radioButton t:"US Letter"];
- else if paperSize = "USLegal"
- select [radioButton t:"US Legal"];
- else if paperSize = "A4Letter"
- select [radioButton t:"A4 Letter"];
- else if ((paperSize = "B5Letter") and (not (printerType = "ImageWriter")))
- select [radioButton t:"B5 Letter"];
- else println "### Unknown paper size specified! No action taken!";
- end;
- end;
-
- (************************************************************************************
- * Task SetScale(scale := 100, printerType := "LaserWriter")
- * To be used by pageSetup() ... see below.
- * Will set the scaling factor for the printer.
- ************************************************************************************)
- task SetScale(scale := 100, printerType := "LaserWriter")
- begin
- if (printerType = "LaserWriter")
- begin
- FindObjectInWindow(133, 71);
- doubleClick;
- type k:{scale};
- end;
- else if ((printerType = "StyleWriter") and ((scale mod 20) = 0))
- begin
- match [window o:1 r:?winPosition];
- scaleTextBox := {(winPosition[1]+272), (winPosition[2]+84),
- (winPosition[3]-186), (winPosition[4]-32)};
- FindObjectInWindow(318, 86);
- match [staticText t:?currentScale r:scaleTextBox e:true];
- while (currentScale <> "100")
- begin
- pressMouse;
- releaseMouse;
- match [staticText t:?currentScale r:scaleTextBox e:true];
- end;
- FindObjectInWindow(318, 98);
- targetScale := numToStr(scale);
- while (currentScale <> targetScale)
- begin
- pressMouse;
- releaseMouse;
- match [staticText t:?currentScale r:scaleTextBox e:true];
- end;
- end;
- else if ((printerType = "ImageWriter") and ((scale mod 50) = 0))
- begin
- match [checkBox t:"50 % Reduction" s:?boxSetting];
- if ((boxSetting[1] = 0) and (scale <> 100))
- select [checkBox t:"50 % Reduction"];
- else if ((boxSetting[1] = 1) and (scale <> 50))
- select [checkBox t:"50 % Reduction"];
- end;
- else println "### Unsupported printer type, scale setting, or both!";
- end;
-
- (************************************************************************************
- * Task SetOrientation(orientation := "portrait", printerType := "LaserWriter")
- * To be used by pageSetup() ... see below.
- * Will set the page orientation in the Page Setup dialog.
- * buttonLocations is a list of the different printers supported.
- * { LaserWriter, StyleWriter, ImageWriter }
- * The list for each printer is another list of coordinates for the corresponding
- * buttons of the form { portrait buton x, landscape button x, both button's y}
- *
- * Failure for this task will return either 1 or 2 to signify a problem.
- *
- ************************************************************************************)
- task SetOrientation(orientation := "portrait", printerType := "LaserWriter")
- begin
- if ((orientation = "portrait") or (orientation = "landscape"))
- begin
- buttonLocations := { {81, 112, 134}, {120, 158, 100}, {29, 67, 118} };
- match [window o:1 r:?winPosition];
- if (printerType = "LaserWriter")
- orientationPosition := buttonLocations[1];
- else if (printerType = "StyleWriter")
- orientationPosition := buttonLocations[2];
- else if (printerType = "ImageWriter")
- orientationPosition := buttonLocations[3];
- else
- begin
- println "### Unsupported printer type ", printerType, "!";
- return 2;
- end;
- if (orientation = "portrait")
- begin
- FindObjectInWindow(orientationPosition[1],orientationPosition[3]);
- click;
- end;
- else
- begin
- FindObjectInWindow(orientationPosition[2], orientationPosition[3]);
- click;
- end;
- end;
- else
- begin
- println "### Unsupported orientation type ", orientation,"!";
- return 1;
- end;
- end;
-
- (************************************************************************************
- * Task PageSetup(printerType, paperSize, scale, orientation)
- * Handle Page Setup Dialog for multiple printers. The following parameters are to
- * be given as strings, except the scale value which is an integer.
- * Supported printer types: LaserWriter
- * ImageWriter
- * StyleWriter
- * Supported page sizes: USLetter
- * USLegal
- * A4Letter
- * B5Letter
- * Supporeted scale values: any integer for LaserWriters
- 50 or 100 for ImageWriters
- any multiple of 20 for StyleWriters
- * Supported orientations: portrait
- * landscape
- *
- * This task will do _some_ checking for value validity. Use of the scale value
- * must be with care as it will not check for an appropriate range, such as a value
- * of zero or values greater than 100 on StyleWriters and ImageWriters.
- ************************************************************************************)
- task PageSetup(printerType := "LaserWriter", paperSize := "USLetter", scale := 100,
- orientation := "portrait")
- begin
- makePageSetupActive();
- setPaper(paperSize, printerType);
- setScale(scale, printerType);
- setOrientation(orientation, printerType);
- select [button t:"OK"];
- end;
-
-